﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CryptoFiles.Common;
using CryptoFiles.Logic;

namespace CryptoFiles.Web
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btRegister_Click(object sender, EventArgs e)
        {
            string login = txLogin.Text;
            string passwd = txPasswd.Text;
            string repeatPasswd = txRepeatPasswd.Text;

            try
            {
                CryptoUser.CreateNewUser(login, passwd, repeatPasswd);
                Response.Redirect("Login.aspx");
            }
            catch (UserRegistrationException ex)
            {
                lbError.Visible = true;
                lbError.Text = "Ошибка: " + ex.Message;
                lbError.ForeColor = Color.Red;


                lbLogin.ForeColor = lbPasswd.ForeColor = lbRepeatPasswd.ForeColor = Color.Black;

                if (ex.Error == ErrorType.EmptyLogin || ex.Error == ErrorType.LoginExists)
                    lbLogin.ForeColor = Color.Red;

                if (ex.Error == ErrorType.EmptyPasswd)
                    lbPasswd.ForeColor = Color.Red;

                if (ex.Error == ErrorType.PasswdMismatch)
                    lbRepeatPasswd.ForeColor = Color.Red;
            }
            
        }
    }
}